package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
@Entity
public class District extends BaseObject {
	private Long id;
    private String name;
    private City city;
    @Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id).append("name", name)
				.append("city", city).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof District))
			return false;
		District castOther = (District) other;
		return new EqualsBuilder().append(name, castOther.name)
				.append(city, castOther.city).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(name).append(city).toHashCode();
	}

	@Id
    @GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@ManyToOne(cascade={CascadeType.MERGE})
	@JoinColumn(name="cityId")
	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

}
